package cn.itheima.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author: cuisensen
 * data: 2018/7/2.
 * time: 12:20.
 */
public class SqlSessionFactoryUtils {
    private static SqlSessionFactory sqlSessionFactory=null;
    static{
        String source="sqlMapConfig.xml";
        InputStream in= null;
        try {
            in = Resources.getResourceAsStream(source);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
    }
    public static SqlSession getSession(){
        return sqlSessionFactory.openSession();
    }
}
